/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Andre
 */
@Entity
@Table(name = "compra")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Compra.findAll", query = "SELECT c FROM Compra c"),
    @NamedQuery(name = "Compra.findByIdCompra", query = "SELECT c FROM Compra c WHERE c.idCompra = :idCompra"),
    @NamedQuery(name = "Compra.findByData", query = "SELECT c FROM Compra c WHERE c.data = :data"),
    @NamedQuery(name = "Compra.findByPerDesconto", query = "SELECT c FROM Compra c WHERE c.perDesconto = :perDesconto")})
public class Compra implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idCompra", nullable = false)
    private Integer idCompra;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "data", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date data;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "perDesconto", nullable = false)
    private double perDesconto;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "compra")
    private List<Itenscompra> itenscompraList;
    
    @JoinColumn(name = "idFornecedor", referencedColumnName = "idPessoa", nullable = false)
    @ManyToOne(optional = false)
    private Fornecedor fornecedor;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "compra")
    private List<Condicoescompra> condicoescompraList;

    public Compra() {
    }

    public Compra(Integer idCompra) {
        this.idCompra = idCompra;
    }

    public Compra(Integer idCompra, Date data, double perDesconto) {
        this.idCompra = idCompra;
        this.data = data;
        this.perDesconto = perDesconto;
    }

    public Integer getIdCompra() {
        return idCompra;
    }

    public void setIdCompra(Integer idCompra) {
        this.idCompra = idCompra;
    }

    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public double getPerDesconto() {
        return perDesconto;
    }

    public void setPerDesconto(double perDesconto) {
        this.perDesconto = perDesconto;
    }

    @XmlTransient
    public List<Itenscompra> getItenscompraList() {
        return itenscompraList;
    }

    public void setItenscompraList(List<Itenscompra> itenscompraList) {
        this.itenscompraList = itenscompraList;
    }

    public Fornecedor getFornecedor() {
        return fornecedor;
    }

    public void setFornecedor(Fornecedor fornecedor) {
        this.fornecedor = fornecedor;
    }

    @XmlTransient
    public List<Condicoescompra> getCondicoescompraList() {
        return condicoescompraList;
    }

    public void setCondicoescompraList(List<Condicoescompra> condicoescompraList) {
        this.condicoescompraList = condicoescompraList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCompra != null ? idCompra.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Compra)) {
            return false;
        }
        Compra other = (Compra) object;
        if ((this.idCompra == null && other.idCompra != null) || (this.idCompra != null && !this.idCompra.equals(other.idCompra))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Compra[ idCompra=" + idCompra + " ]";
    }
    
}
